package com.wlz.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;

/**
 * @author： wlz
 * @Date 2020/10/22 15:49
 * @description： TODO
 * @version: 1.0
 */
public class Util {

    public static JSONObject so(String mobile) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", 0);//多少人标识
        try {
            Connection con = Jsoup.connect("https://www.so.com/s?q=" + mobile);
            con.header("Host", "https://www.so.com");
            con.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            con.header("Content-Type", "application/x-www-form-urlencoded");
            con.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
            Document doc = con.get();
            String count = doc.select(".mohe-tips b").text();
            if (StringUtils.isNotBlank(count)) {
                jsonObject.put("count", count);//多少人标识
                jsonObject.put("address", doc.select(".mohe-mobileInfoContent .mh-detail span").last().text());//地址
                jsonObject.put("type", doc.select(".mohe-tips .mohe-ph-mark").text());//标识类别
                jsonObject.put("source", doc.select(".mohe-tips .mohe-sjws").text());//来源
//                jsonObject.put("date", EasyDate.getCurrentDateString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            return jsonObject;
        }
        return jsonObject;
    }

    public static JSONObject baidu(String mobile) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", 0);//多少人标识
        try {
            Connection con = Jsoup.connect("https://www.baidu.com/user_code_info?cid=" + mobile);
//            Connection con = Jsoup.connect("https://www.baidu.com/s?wd=" + mobile);
            con.header("Host", "www.baidu.com");
            con.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
            con.header("Content-Type", "application/x-www-form-urlencoded");
            con.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
            Document doc = con.get();
            String source = doc.select(".op_fraudphone_word a").text();
            if (StringUtils.isNotBlank(source)) {
                jsonObject.put("source", doc.select(".op_fraudphone_word a").text());//来源
                String desc = doc.select(".op_fraudphone_word").text();
                if (StringUtils.isNotBlank(desc)) {
                    String count = desc.substring(desc.indexOf("被") + 1, desc.indexOf("个"));
                    jsonObject.put("count", count);//多少人标识
                }
                jsonObject.put("address", doc.select(".op_fraudphone_addr").text());//地址
                jsonObject.put("type", doc.select(".op_fraudphone_label").text());//标识类别
//                jsonObject.put("date", EasyDate.getCurrentDateString());
            }
        } catch (Exception e) {
            e.printStackTrace();
            return jsonObject;
        }
        return jsonObject;
    }

    public static void main(String[] args) throws IOException {
        // String mobile="073184145266";
            String mobile = "3744b72d5607593ea3779f6fcb8a51a0974cca39";
            System.out.println(baidu(mobile));
//            System.out.println(so(mobile));

    }
}
